package chabernac.android.wordbattle.paint;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;

public abstract class AbstractBitmapDrawable extends iDrawable {
  
  protected final int myX;
  protected final int myY;
  protected final int myWidth;
  protected final int myHeight;
  protected final int myAlpha;
  
  private Bitmap myBitmap = null;
  protected final Paint myPaint;
  
  public AbstractBitmapDrawable(int aX, int aY, int aWidth, int aHeigth, int anAlpha) {
    super();
    myX = aX;
    myY = aY;
    myWidth = aWidth;
    myHeight = aHeigth;
    myAlpha = anAlpha;
    myPaint = new Paint();
  }

  @Override
  public void paint(Canvas aCanvas, View aView) {
    if(myBitmap == null){
      myBitmap = Bitmap.createBitmap( myWidth, myHeight, Bitmap.Config.ARGB_8888 );
      doPaint(new Canvas(myBitmap));
    }
    myPaint.setAlpha(myAlpha);
    aCanvas.drawBitmap(myBitmap, myX, myY, myPaint);
  }
  
  protected abstract void doPaint(Canvas aCanvas);

  public int getX() {
    return myX;
  }

  public int getY() {
    return myY;
  }

  public int getWidth() {
    return myWidth;
  }

  public int getHeight() {
    return myHeight;
  }

}
